import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/login/Login.vue'
import Home from '../views/Home.vue'

import Macro from "../views/pages/monitor/Macro.vue";
import Micro from "../views/pages/monitor/Micro.vue";
import Photo from "../views/pages/monitor/Photo.vue";
import Duty from "../views/pages/other/Duty.vue";
import Warnings from "../views/pages/other/Warnings.vue";
import Host from "../views/pages/host/Host.vue";
import Webshell from "../views/pages/host/HostWebshell.vue";
import Project from "../views/pages/project/Project.vue";
import Reptile from "../views/pages/reptile/Reptile.vue";
import Author from "../views/pages/system/Author.vue";
import Log from "../views/pages/system/Log.vue";
import Power from "../views/pages/system/Power.vue";
import DutyPlan from "../views/pages/system/DutyPlan.vue";
import Warning from "../views/pages/system/Warning.vue";
import Watch from "../views/pages/system/Watch.vue";
import Task from "../views/pages/task/Task.vue";
import Classification from "../views/pages/system/Classification.vue";
import notfound from "../views/pages/404notfound/404Notfound.vue";

Vue.use(VueRouter)

const routes = [

  {
    path: '/',
    redirect: "/Login",
  },
  {
    path: '/Login',
    name: "Login",
    component: Login
  },
  {
    path: '/Home',
    name: "Home",
    component: Home,
    redirect: '/Macro',
    children: [
      { path: "/Macro", component: Macro },
      { path: "/Micro", component: Micro },
      { path: "/Photo", component: Photo },
      { path: "/Project", component: Project },
      { path: "/Author", component: Author },
      { path: "/Log", component: Log },
      { path: "/DutyPlan", component: DutyPlan },
      { path: "/Watch", component: Watch },
      { path: "/Reptile", component: Reptile },
      { path: "/Host", component: Host },
      { path: "/Warning", component: Warning },
      { path: "/Warnings", component: Warnings },
      { path: "/Duty", component: Duty },
      { path: "/Power", component: Power },
      { path: "/Task", component: Task },
      { path: "/Classification", component: Classification },
      // { path: '/abnormalReptile', name: "abnormalReptile", component: Reptile },
      // { path: "/Deploy", component: Deploy },
    ]
  },
  { path: '/webshell', name: "webshell", component: Webshell },

  {
    path: '*',
    component: notfound
  },

]

const router = new VueRouter({
  routes
})

// 路由导航守卫
router.beforeEach((to, from, next) => {
  // to将要访问的路径  from从哪个路径跳转而来  next()是一个函数，代表放行
  // next() 放行 next('/login') 强制跳转
  if (to.path === '/login') return next();
  // 获取token
  const tokenStr = window.sessionStorage.getItem('token');
  if (!tokenStr) return next('/login')
  next()
})

export default router
